<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: linear-gradient(to right, violet, rgb(240, 214, 253));
        position: absolute;
        top: 0;
        left: 0;
      }
    </style>
  </head>
  <body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </body>
  <script>
    let fly = document.querySelectorAll("div");
    document.addEventListener("mousemove", function (e) {
      fly[0].style.top = e.clientY - fly[0].offsetHeight / 2 + "px";
      fly[0].style.left = e.clientX - fly[0].offsetWidth / 2 + "px";
      for (let i = fly.length - 1; i > 0; i--) {
        fly[i].style.top = fly[i - 1].style.top;
        fly[i].style.left = fly[i - 1].style.left;
      }
      let t = setInterval(function () {
        for (let i = 0; i < fly.length; i++) {
          if (
            parseInt(fly[i].style.top) == 0 &&
            parseInt(fly[i].style.left) == 0
          ) {
            fly[i].style.top = fly[0].style.top;
            fly[i].style.left = fly[0].style.left;
          }
        }
      }, 10);
      clearInterval(t);
    });
  </script>
</html>
